package com.zhao.uitest;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.zhao.uitest.chat_ui.ChatActivity;
import com.zhao.uitest.listview.ListViewLayout;

public class MainActivity extends BaseActivity {
    private Button mBt_1;
    private Button mBt_2;
    private Button mBt_listview;
    private Button mBt_chat;
    private TextView mTv;
    private ProgressBar mPb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        tag("onCrate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        mBt_1 = (Button) findViewById(R.id.bt_1);
        mBt_2 = (Button) findViewById(R.id.bt_2);
        mTv = (TextView) findViewById(R.id.tv);
        mPb = (ProgressBar) findViewById(R.id.pb);
        mBt_listview = (Button) findViewById(R.id.bt_listview);
        mBt_chat = (Button) findViewById(R.id.bt_chat_ui);

        mBt_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /**
                 * 设置进度条
                 */
                tag("onClick");
                if (mPb.getVisibility() != View.VISIBLE) {
                    mPb.setProgress(0);
                    mPb.setVisibility(View.VISIBLE);
                    return;
                }
                int ProgressBarValue = mPb.getProgress();
                tag("ProgressBarValue:"+ProgressBarValue);
                if (ProgressBarValue>=100){
                    mPb.setVisibility(View.GONE);
                    return;
                }
                mPb.setProgress(ProgressBarValue+10);
                mTv.setText("Value = %"+(ProgressBarValue+10));
            }
        });

        mBt_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tag("Button 2 onClicked");
                /**
                 * 弹出对话框
                 */
                AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
                dialog.setTitle("My AlertDialog");
                dialog.setMessage("AlertDialog Message");
                dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        tag("NegativeButton");
                    }
                });
                dialog.show();
            }
        });

        mBt_listview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ListViewLayout.class);
                startActivity(intent);
            }
        });

        mBt_chat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ChatActivity.class);
                startActivity(intent);
            }
        });
    }
}
